home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 473 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: tottinge@csci.csc.com (Tim Ottinger)
  3. Newsgroups: comp.std.c++
  4. Subject: OSTRSTREAM and sizing
  5. Date: 23 Feb 1996 23:27:35 GMT
  6. Organization: CSC CIS - TRIS DIVISION
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4glcfq$sfr@venus.roc.csci.csc.com>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Content-Type: text
  11. Summary: How to determine size of strbuffer?
  12. X-Nntp-Posting-Host: pccom9-156.csci.csc.com
  13. X-Newsreader: News Xpress Version 1.0 Beta #3
  14. Content-Length: 1669
  15. X-Lines: 45
  16. Originator: clamage@taumet
  17.  
  18. Hi.
  19.  
  20. This might be a silly question, but a coworker of mine noticed this, and we've 
  21. tested it on two compilers with similar results:
  22.  
  23.     #include <iostream.h>
  24.     #include <strstream.h>
  25.     int main (char * argc, char * argv[])
  26.     {
  27.        ostrstream str("abcdefg", 4);
  28.    
  29.        cout << "Length = " << str.pcount() << endl;
  30.        cout << "Data   = " << str.str();
  31.     }
  32.  
  33. produces the following output on both the GNU and HP C++ compilers
  34.     Length = 0
  35.     Data   = abcdefg
  36.  
  37. Two things were puzzling about this.  
  38.  
  39. The first was that the length parameter on the c'tor didn't seem 
  40. to be used for anything, and the second was that I couldn't spot the 
  41. right way to tell how big the buffer in the strstreambuf is (how many 
  42. actual characters are in it).
  43.  
  44. It seems that "data" should have returned either "abcd", or "", 
  45. rather than "abcdefg".  This tossed me.
  46.  
  47. My friend expected the 'pcount()' to tell him how many bytes are in
  48. the buffer.
  49.  
  50. I can see some of this for istream(), though much still eludes.  For
  51. an ostream, this is somewhat maddening.
  52.  
  53. Is is standard, and does it make sense?
  54.  
  55. ******************************************************************************
  56. * Tim Ottinger, Sr Tech                       tottinge@csci.csc.com *
  57. * CSC Communications Industry Services                   217-351-8508x2420 *
  58. * TRIS Division -- Cellular Billing and Support                Fax 217-351-2640 *
  59. ******************************************************************************
  60. * Requirements have always been the least stable part of any project I have  *
  61. * worked upon.                            -- Robert Martin via Usenet 12/02/95 *
  62. ******************************************************************************
  63.  
  64. [ To submit articles: Try just posting with your newsreader.
  65.               If that fails, use mailto:std-c++@ncar.ucar.edu
  66.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  67.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  68.   Comments? mailto:std-c++-request@ncar.ucar.edu
  69. ]
  70.